!<template>
    <div class="content-main">
        <div class="breadcrumb">
            <div class="breadcrumb-icon">
                <img src="./../../assets/images/breadcrumb_icon.png" />
            </div>
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>镜像管理</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
          <div class="content-box">
             <div class="search-box">
                <div class="search-item">
                    <span class="search-title">镜像名称: </span>
                    <el-input v-model="imageValue" placeholder="请输入镜像名称" style="float:left; width:auto;"></el-input>
                </div>
                <div class="search-item">
                    <el-button type="primary" @click="searchFn">搜索</el-button>
                </div>
                <div class="search-item" style="float:right; margin:0;">
                    <el-button type="primary" @click="deleteList">批量删除</el-button>
                </div>
            </div>
            <div class="table-content">
                <el-table
                :data="tableData"
                border
                ref="multipleTable"
                style="width: 100%"
                @selection-change="handleSelectionChange">
                <el-table-column type="selection" width="100px">
                </el-table-column>
                <el-table-column prop="publicName" label="镜像名称">
                </el-table-column>
                <el-table-column prop="status" label="状态">
                    <template slot-scope="scope">
                        {{scope.row.status==true?'使用':'未使用'}}
                    </template>
                </el-table-column>
                <el-table-column prop="userName" label="制作人">
                </el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <el-button type="text" size="small" @click="lookManger(scope.row.id,scope.row.publicName,scope.row.userName,scope.row.introduction)">查看镜像信息</el-button>
                    </template>
                </el-table-column>
                </el-table>
                <el-pagination
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    :current-page="currentPage"
                    :page-size="pagesize"
                    layout="total, prev, pager, next, jumper"
                    :total="totalCount"
                    style="margin-top: 20px; text-align: center;">
                </el-pagination>
            </div>
                <el-dialog class="add-virtual-dialog" title="镜像信息" :visible.sync="dialogFormVisible" width='500px'>
                    <span class="count" v-if="introduction != '' && introduction != null"  style='word-wrap:break-word' >{{introduction}}</span>
                    <span v-else-if="introduction == '' ||  introduction == null " style='word-wrap:break-word' >暂无镜像信息</span>
                     <div slot="footer" style="text-align:center;">
                        <el-button type="primary" @click="close" >关闭</el-button>
                    </div>
                </el-dialog>
    
         </div>
    </div>
</template>

<script>
    export default {
        data(){
            return{
                id:'',
                imageValue:'',
                tableData: [],
                currentPage:1,
                pagesize:10,
                totalCount: 1000,
                multipleSelection: [],
                dialogFormVisible: false,
                introduction:''
             
            }
        },
        created() {
            this.init()
        },
        methods: {
            init(){
                let self = this
                self.$http.get('/dataplatform/image/listImage?pageNum='+self.currentPage+'&pagesize='+self.pagesize+'&imageName='+self.imageValue).then((response) => {
                    let res = response.data
                    if(res.code == '200') {
                       self.tableData = res.data.list
                       self.totalCount = res.data.total
                    }else if(res.code == '401'){
                        self.$router.replace({
                            path:'/login'
                        })
                    }else{
                        self.$message.error(res.message)
                    }
                })
            },
            //查看镜像信息
            lookManger(id,publicName,userName,introduction){
                this.dialogFormVisible=true
                this.id=id
                this.introduction=introduction
                
            },
            //关闭信息
            close(){
               this.dialogFormVisible=false   
            },
           //批量删除
           deleteList(){
             let self = this;
				if(self.multipleSelection.length == 0){
                    self.$message({
                        message: '请选择要删除的镜像',
                        type: 'warning'
                    })
					return
                }
                // let idList = ''
				// for(let item in self.multipleSelection){
				// 	if(item == 0){
				// 		idList = self.multipleSelection[item]
				// 	}else{
				// 		idList = idList + '&' + 'idList='+self.multipleSelection[item]
                //     }
                // }
				self.$confirm('是否删除选中?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					self.$http.get('/dataplatform/image/deleteImage?imageIds='+self.multipleSelection).then((response) => {
						let res = response.data;
						if(res.code == '200'){
                            self.$message({
                                message: '删除成功',
                                type: 'success'
                            })
							self.init()
						}else if(res.code == '401'){
                            self.$router.replace({
                                path:'/login'
                            })
                        }else{
                            self.$message.error(res.message)
                        }
					},(err) => {
						console.log('err');
					})
				}).catch(() => {
				})
           },
           //搜索
           searchFn(){
                this.currentPage = 1
                this.init()
           },
           //表格分页
			handleSizeChange: function (size) {
				this.pagesize = size;
			},
			handleCurrentChange: function(currentPage) {
                this.currentPage = currentPage
                this.init()
            },
            //全选
			handleSelectionChange(val) {
				let valArr = []
				for(let i = 0; i < val.length; i++){
					valArr.push(val[i].id)
				}
				this.multipleSelection = valArr
            },
           
        }
    }
</script>